package ui.swing.dialog;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

import ui.swing.Console;

public class Dialogs extends JApplet {

	private JButton b1 = new JButton("Dialog Box");

	private MyDialog dlg = new MyDialog(null);

	@Override
	public void init() {
		b1.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				dlg.setVisible(true);
			}
		});
		getContentPane().add(b1);
	}

	public static void main(String[] args) {
		Console.run(new Dialogs(), 125, 75);
	}
}

class MyDialog extends JDialog {
	public MyDialog(JFrame parent) {
		super(parent, "MyDialog", true);
		Container cp = getContentPane();
		cp.setLayout(new FlowLayout());
		cp.add(new JLabel("Here is my dialog"));

		JButton btnOk = new JButton("OK");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose(); // close the dialog
			}
		});
		cp.add(btnOk);
		setSize(150, 125);
	}
}